import '../../util/_base_export.dart';
import '../../util/_view_export.dart';

import '../../blocs/order_detail.dart';
import '../../blocs/cart.dart';
import '../../util/app_util.dart';

class SelectWhPage extends StatefulWidget {
  const SelectWhPage({Key? key}) : super(key: key);
  @override
  _SelectWhPageState createState() => _SelectWhPageState();
}

class _SelectWhPageState extends State<SelectWhPage> {
  @override
  void initState() {
    super.initState();
  }

  List<Widget> list = List<Widget>.empty(growable :true);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        brightness: Brightness.light,
        title: Text('选择区域', style: TextStyle(color: AppColor.blackMain)),
      ),
      body: SingleChildScrollView(
        child: Container(
          child: _channel_list(context),
        ),
      ),
    );
  }

  Widget _channel_list(BuildContext context) {
    OrderDetailBloc _orderDetail =
        Provider.of<OrderDetailBloc>(context, listen: false);
    list.clear();
    for (var lv_wh in AppSession.appUtil.wh_list) {
      list.add(GestureDetector(
        onTap: () async {
          await AppSession.setWhid(lv_wh['wh_id']);
          App.router.navigateTo(context, AppRoutes.appMain, replace: true);
        },
        behavior: HitTestBehavior.opaque,
        child: ListTile(
          contentPadding:
              EdgeInsets.symmetric(horizontal: 26.w, vertical: 10.h),
          leading: Icon(Icons.location_city),
          title: Text(
            lv_wh['name'],
            style: TextStyle(fontSize: 15.sp),
          ),
          trailing: Icon(Icons.chevron_right, size: 36),
        ),
      ));
    }
    return Column(children: list);
  }
}
